package com.effectiv.gooruda.rest.service.impl;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;

import com.effectiv.gooruda.rest.docs.pojo.RestApiDoc;
import com.effectiv.gooruda.rest.docs.util.RestApiDocUtils;


@Component
@Path("/apidocs")
public class APIDocServiceImpl {
	@Autowired
	private ServletContext servletContext;
	private String version = "0.0.3";
	private String basePath = "http://127.0.0.1:8080/api3";

	private RestApiDoc restApiDoc = null;
	
	public void setVersion(String version) {
		this.version = version;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}
		
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public @ResponseBody
	RestApiDoc getApi() {
		
		if(restApiDoc == null){
			restApiDoc = RestApiDocUtils.getApiDoc(servletContext, version, basePath);
		}
		
		return restApiDoc;
	}

}
